<template>
    <el-form :inline="inline" :model="form" ref="form" label-width="100px" v-loading="config.loading">
        <el-form-item v-for="v in formLabel" :key="v.model" :label="v.label">
            <el-input v-model="form[v.model]" :placeholder="'请输入' + v.label" v-if="!v.type"></el-input>
            <el-select v-model="form[v.model]" placeholder="请选择" v-if="v.type === 'select'">
                <el-option v-for="(v2, k2) in v.opts" :key="k2" :label="v2" :value="k2"></el-option>
            </el-select>
            <el-switch v-model="form[v.model]" v-if="v.type === 'switch'"></el-switch>
            <el-date-picker v-model="form[v.model]" :type="v.dateType ? v.dateType : datetime" placeholder="选择日期" v-if="v.type === 'date'" value-format="timestamp" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>
        <el-form-item><slot></slot></el-form-item>
    </el-form>
</template>

<script>
    export default {
        props: {
            inline: Boolean,
            form: Object,
            formLabel: Array,
            config: Object
        },
        data() {
            return {
                datetime: 'datetime',
                pickerOptions: {
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
            }
        },
    }
</script>

<style lang="scss" scoped></style>
